#!/usr/bin/env node

const cp = require('child_process')

console.log('I am father process. PID:', process.pid)

const son = cp.fork('./11-ipc-child.js'),
      dau = cp.fork('./11-ipc-child.js')

son.on('message', (msg) => {
      console.log(`I have a son with PID: ${msg}`)
})

dau.on('message', (msg) => {
  console.log(`I have a daughter with PID: ${msg}`)
})

setTimeout(() => {
    son.send('good good study');
}, 2000);

setTimeout(() => {
    dau.send('day day up');
}, 4000);

setTimeout(() => {
    son.kill('SIGINT');
    dau.kill('SIGINT');
    process.exit();
}, 6000);
